package com.lhy.multipledatasources.service;// OrderService.java

import com.lhy.multipledatasources.entity.Order;
import com.lhy.multipledatasources.mapper.secondary.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderService {

    private final OrderMapper orderMapper;

    @Autowired
    public OrderService(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    public Order getOrderByNumber(String orderNumber) {
        return orderMapper.selectByOrderNumber(orderNumber);
    }

    public List<Order> getOrdersByUser(Long userId) {
        return orderMapper.selectByUserId(userId);
    }

    @Transactional(transactionManager = "secondaryTransactionManager")
    public int createOrder(Order order) {
        return orderMapper.insert(order);
    }

    @Transactional(transactionManager = "secondaryTransactionManager")
    public int updateOrderStatus(String orderNumber, int status) {
        return orderMapper.updateStatus(orderNumber, status);
    }
}